<?php
/*IMPORTANT: 注意检查文件字符集是否为UTF-8*/
include "./config/util.conf.php";
function UtilFuncEncryptUserPassword($strPwd)
{
	global $userPasswordEncryptCode;
	return md5(sha1($strPwd).$userPasswordEncryptCode);
}

function UtilFuncInComingStringFilter($strIn)
{
	return addslashes($strIn);
}

function UtilFuncOutGoingStringFilter($strOut)
{
	return htmlspecialchars($strOut);
}

function UtilFuncGenerateUuid()
{
	return trim(com_create_guid(),"{}");
}

function UtilFuncGetIpAddress()
{
	return $_SERVER['REMOTE_ADDR'];
}

function UtilFuncGetArrayHTML($array,$escapeTailCRLF=true)
{
	$i=0;
	$ret = "";
	foreach ($array as $element)
	{
		if($i>0)
		{
			$ret .= ", ";
		}
		++$i;
		$ret .= $element;
	}
	return htmlentities($ret);
}
function UtilFuncGetArrayTableRowsHTML($array,$escapeTailCRLF=true)
{
	$i=0;
	$ret = "";
	foreach ($array as $element)
	{
		$token = strtok($element, ":");
		$ret .= "<tr><td>".htmlentities($token).":</td>";
		$token = strtok(",");
		$ret .="<td>".str_replace("#|#","<br />",htmlentities($token))."</td></tr>";
	}
	return $ret;
}
function UtilFuncCommonRedir($loc)
{
	header("Location: {$loc}");
}
function UtilFuncSigninRedir()
{
	if(isset($_SERVER['HTTP_REFERER']))
	{
		$path = $_SERVER['HTTP_REFERER'];
		header("Location: ".$path);
	}
	else
	{
		header("Location: ./");
	}
}
function UtilFuncGoSigninRedir($uri)
{
	$redir = rawurlencode($uri);
	header("Location: ./signin.php?path=".$redir);
}
function UtilFuncGetRequestQueryParam_path($query)
{
	parse_str($query);
	if(@$path)
	{
		return $path;
	}
	return "%2F";
}
function UtilFuncGetCurrentRequestURI()
{
	return @$_SERVER['REQUEST_URI'];
}
if (!function_exists('com_create_guid'))
{
	function com_create_guid()
	{
		mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
 		$charid = strtoupper(md5(uniqid(rand(), true)));
  		$hyphen = chr(45);// "-"
		$uuid = substr($charid, 0, 8).$hyphen.substr($charid, 8, 4).$hyphen.substr($charid,12, 4).$hyphen.substr($charid,16, 4).$hyphen.substr($charid,20,12);
     	return $uuid;
	}
}
?>